using System;
using System.Collections.Generic;
using System.Text;
using gudusoft.gsqlparser;
using gudusoft.gsqlparser.Units;

namespace getrawstatements
{
    class getrawstatements
    {
        static void Main(string[] args)
        {
            // create a sql parser instance supports ms sql server sql dialect
            TGSqlParser sqlparser = new TGSqlParser(TDbVendor.DbVOracle);//DbVMssql

            //sqlparser.SqlText.Text = "select dummyfield from dummytable;delete from dummytable;update dummytable set dummyfield=1";
            //sqlparser.SqlText.Text = "SELECT * FROM users WHERE name = 'a'; DROP TABLE users; SELECT * FROM userinfo WHERE 't' = 't';";
            sqlparser.SqlText.Text = "create table a (no number )" + Environment.NewLine +
"/" + Environment.NewLine +
"create table b (no number )";

            int iRet = sqlparser.GetRawSqlStatements();
            if (iRet == 0)
            {
                foreach(TCustomSqlStatement sql in sqlparser.SqlStatements){
                    Console.WriteLine("sql type: {0}",sql.SqlStatementType);
                    Console.WriteLine("sql text: {0}",sql.RawSqlText);
                }
            }
            else
            {
                Console.WriteLine("Syntax error found in input sql:");
                Console.WriteLine(sqlparser.ErrorMessages);
            }
        }
    }
}
